package com.tarena.lbs.attach.dao.repository.impl;

import com.tarena.lbs.attach.dao.mapper.AttachMapper;
import com.tarena.lbs.attach.dao.repository.AttachRepository;
import com.tarena.lbs.attach.pojo.po.AttachPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
public class AttachRepositoryImpl implements AttachRepository {

    @Autowired
    private AttachMapper attachMapper;

    @Override
    public int save(AttachPO attachPO) {
        return attachMapper.insert(attachPO);
    }

    @Override
    public AttachPO findById(Integer id) {
        return attachMapper.selectById(id);
    }

    @Override
    public List<AttachPO> findByBusiness(Integer businessType, Integer businessId) {
        return attachMapper.selectByBusiness(businessType, businessId);
    }

    @Override
    public int updateStatus(AttachPO attachPO) {
        return attachMapper.updateStatus(attachPO);
    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return 0;
        }
        String idsStr = ids.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
        // 注意：实际项目中应使用更安全的方式处理IN查询
        return 0; // 需要根据实际需求实现
    }

    @Override
    public int bindBusiness(AttachPO attachPO) {
        return attachMapper.bindBusiness(attachPO);
    }
}
